package com.crl.module.abcDecoder
{
	import com.codeazur.as3swf.SWF;
	import com.codeazur.as3swf.tags.ITag;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	public class DecoderUtil extends EventDispatcher
	{
		public function DecoderUtil()
		{
		}
		
		public function decode(path:String):void{
			var request:URLRequest = new URLRequest(path);
			var loader:URLLoader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.addEventListener(Event.COMPLETE, completeToDeleteClassHandler);
			loader.load(request);
		}
		
		private function completeToDeleteClassHandler(e:Event):void{
			var bytes:ByteArray=URLLoader(e.target).data as ByteArray;
			swf= new SWF(bytes);
			
			this.dispatchEvent(e);
		}
		private var swf:SWF;
		public function getTags(cls:Class=null):Vector.<ITag>{
			var tags:Vector.<ITag>=swf.tags;
			
			var result:Vector.<ITag>=new Vector.<ITag>();
			for each(var tag:ITag in tags){
				if(cls ){
					if(tag is cls){
						result.push(tag);
					}
					continue;
				}
				result.push(tag);
			}
			return result;
		}
	}
}